
export default {
	
	/**
	 * 计算两个经纬度之间的距离
	 * @param {Object} lat1
	 * @param {Object} lng1
	 * @param {Object} lat2
	 * @param {Object} lng2
	 */
	getDistance(lat1, lng1, lat2, lng2) {
		var radLat1 = lat1 * Math.PI / 180.0;
		var radLat2 = lat2 * Math.PI / 180.0;
		var a = radLat1 - radLat2;
		var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
		var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
			Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
		s = s * 6378.137; // EARTH_RADIUS;
		s = Math.round(s * 10000) / 10000;
		return s;
	},
	
	/**
	 * 确认弹窗
	 * @param {Object} content 内容
	 */
	$confirm(content) {
	    return new Promise((resolve, reject) => {
	        uni.showModal({
				title: '温馨提示',
	            content,
	            success: ({
	                confirm
	            }) => {
	                if (confirm) {
	                    resolve()
	                }
	            }
	        })
	    })
	},
	
	$navigateBack(msg) {
		uni.$u.toast(msg);
		setTimeout(() => {
			uni.navigateBack();
		}, 1000)
	},
	$switchTab(msg, url) {
		uni.$u.toast(msg);
		setTimeout(() => {
			uni.switchTab({
				url: url
			});
		}, 1000)
	},
}